﻿#include "BaseKit.h"
#include "IndexController.h"

static RootWindow* rootWindow=nullptr;

RootWindow::RootWindow():navigation(nullptr){}

RootWindow::~RootWindow(){}

bool RootWindow::init(){
	if(!CAWindow::init()){
		return false;
	}
	font.fontSize=30;
	font.color=ccc4(102, 102, 102, 255);

	CANavigationController* navigation1=new CANavigationController();
	navigation1->setNavigationBarHidden(true, false);
	navigation1->initWithRootViewController(IndexController::create());
	navigation1->setTabBarItem(CATabBarItem::create("菜单1", CAImage::create("img/unselect.png"), CAImage::create("img/select.png")));
	navigation1->autorelease();
	CANavigationController* navigation2=new CANavigationController();
	navigation2->setNavigationBarHidden(true, false);
	navigation2->initWithRootViewController(IndexController::create());
	navigation2->setTabBarItem(CATabBarItem::create("菜单2", CAImage::create("img/unselect.png"), CAImage::create("img/select.png")));
	navigation2->autorelease();
	CANavigationController* navigation3=new CANavigationController();
	navigation3->setNavigationBarHidden(true, false);
	navigation3->initWithRootViewController(IndexController::create());
	navigation3->setTabBarItem(CATabBarItem::create("菜单3", CAImage::create("img/unselect.png"), CAImage::create("img/select.png")));
	navigation3->autorelease();
	CAVector<CAViewController*> views;
	views.pushBack(navigation1);
	views.pushBack(navigation2);
	views.pushBack(navigation3);
	views.autorelease();
	CATabBarController* bar=new CATabBarController();
	bar->initWithViewControllers(views);
	bar->setTitle("CrossApp");
	bar->autorelease();
	navigation=new CANavigationController();
	navigation->initWithRootViewController(bar);
	navigation->setNavigationBarTitleColor(CAColor4B::RED);
	navigation->autorelease();
	this->setRootViewController(navigation);
	CAApplication::getApplication()->setNotificationView(nullptr);

	return true;
}

RootWindow* RootWindow::getInstance(){
	if(rootWindow==nullptr){
		rootWindow=new RootWindow();
		rootWindow->init();
	}

	return rootWindow;
}

void RootWindow::destroyInstance(){
	CC_SAFE_DELETE(rootWindow);
	rootWindow=nullptr;
}